package o;

import android.content.Context;
import android.os.Process;
import com.huawei.appgallery.downloadengine.api.DownloadChkInfo;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.downloadengine.impl.SplitDownloadThreadInfo;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.utils.FileUtil;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.tencent.mm.opensdk.constants.ConstantsAPI.AppSupportContentFlag;
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Future;
import javax.net.ssl.SSLProtocolException;
import o.dom.d;

class bnu implements Runnable {
    private volatile boolean ʻ = true;
    private long ʻॱ = 0;
    boolean ʼ = false;
    private long ʼॱ = 0;
    long ʽ = 0;
    private byte[] ʽॱ = new byte[4097];
    private boolean ʾ = false;
    private boolean ʿ = false;
    private int ˈ = 0;
    private Future<?> ˉ = null;
    Map<String, List<String>> ˊ = new LinkedHashMap();
    private StringBuffer ˊˊ = new StringBuffer();
    private a ˊˋ = null;
    private bnx ˊॱ = null;
    String ˋ = "";
    private boolean ˋˊ = false;
    private SplitTask ˋॱ;
    String ˎ = "";
    String ˏ = "";
    private SplitDownloadThreadInfo ˏॱ;
    private int ͺ = 0;
    String ॱ = "";
    private boolean ॱˊ = false;
    private String ॱˋ = "";
    private long ॱˎ = System.currentTimeMillis();
    private volatile boolean ॱॱ = false;
    private long ॱᐝ = 0;
    long ᐝ = 0;
    private long ᐝॱ = 0;

    class a {
        private int ˊ = 0;
        private MessageDigest ˋ = null;
        final /* synthetic */ bnu ˎ;
        private int ˏ = -1;
        private int ॱ = 0;
        private int ॱॱ = 0;
        private boolean ᐝ = false;

        a(bnu o_bnu) {
            this.ˎ = o_bnu;
        }

        public void ˎ(byte[] bArr, int i, int i2) throws bnj {
            if (this.ˎ.ˋॱ.ʾ() != 1) {
                if (!(this.ᐝ || this.ˎ.ˋॱ.ˍ() == null || this.ˎ.ˋॱ.ˍ().size() <= 0)) {
                    ˎ();
                }
                if (!this.ᐝ) {
                    return;
                }
                if (i2 < this.ॱॱ) {
                    this.ˋ.update(bArr, i, i2);
                    this.ॱ += i2;
                    this.ॱॱ -= i2;
                    return;
                }
                int i3 = this.ॱॱ;
                this.ˋ.update(bArr, i, this.ॱॱ);
                this.ॱ += this.ॱॱ;
                this.ॱॱ = 0;
                if (this.ॱ == this.ˊ) {
                    if (!doa.ˋ(this.ˋ.digest()).equalsIgnoreCase(((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(this.ˏ)).ॱ())) {
                        String str;
                        StringBuilder append = new StringBuilder().append("[package=").append(this.ˎ.ˋॱ.ˎˎ()).append(", sliceIndex=").append(this.ˏ).append(", serverip=").append(this.ˎ.ˎ).append(", lastUrl=").append(this.ˎ.ॱ).append(", checkData=");
                        if (dof.ˋ(this.ˎ.ˋॱ.ʻॱ())) {
                            str = HwAccountConstants.NULL;
                        } else {
                            str = this.ˎ.ˋॱ.ʻॱ();
                        }
                        throw this.ˎ.ˎ(new bnj(122, "checkSlice error : sha256 error " + append.append(str).append("]").toString()));
                    } else if (this.ˎ.ॱ(122)) {
                        throw this.ˎ.ˎ(new bnj(122, "mock slice check failed"));
                    } else {
                        bnc.ˎ.ˋ("HiAppDownload", "check slice ok, index=" + this.ˏ);
                    }
                }
                this.ˋ.reset();
                this.ˏ++;
                if (this.ˏ < this.ˎ.ˋॱ.ˍ().size()) {
                    this.ˊ = (int) ((((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(this.ˏ)).ˋ() - ((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(this.ˏ)).ˎ()) + 1);
                    this.ॱ = 0;
                    this.ॱॱ = this.ˊ;
                    ˎ(bArr, i + i3, i2 - i3);
                }
            }
        }

        private void ˎ() {
            try {
                this.ˋ = MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256);
            } catch (NoSuchAlgorithmException e) {
                bnc.ˎ.ˊ("HiAppDownload", "create sha256 messageDigest failed" + e.getMessage());
            }
            long ʽ = this.ˎ.ˏॱ.ʽ() + this.ˎ.ˏॱ.ʻ();
            int ॱ = ॱ(ʽ + 1);
            if (ॱ >= 0 && ॱ < this.ˎ.ˋॱ.ˍ().size()) {
                this.ˏ = ॱ;
                this.ˊ = (int) ((((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(ॱ)).ˋ() - ((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(ॱ)).ˎ()) + 1);
                this.ॱ = 0;
                this.ॱॱ = (int) (((DownloadChkInfo) this.ˎ.ˋॱ.ˍ().get(ॱ)).ˋ() - ʽ);
                this.ᐝ = true;
                bnc.ˎ.ˋ("HiAppDownload", "slice check inited: currentCheckIndex=" + this.ˏ + ", currentSliceSize=" + this.ˊ);
            }
        }

        private int ॱ(long j) {
            List ˍ = this.ˎ.ˋॱ.ˍ();
            int i = 0;
            while (i < ˍ.size()) {
                if (j >= ((DownloadChkInfo) ˍ.get(i)).ˎ() && j <= ((DownloadChkInfo) ˍ.get(i)).ˋ()) {
                    return i;
                }
                i++;
            }
            return -1;
        }
    }

    static class e {
        private long ˊ;
        private long ˋ;
        private long ˎ;
        private long ˏ;
        private InputStream ॱ;

        public InputStream ˊ() {
            return this.ॱ;
        }

        public void ˎ(InputStream inputStream) {
            this.ॱ = inputStream;
        }

        public long ˏ() {
            return this.ˊ;
        }

        public void ˏ(long j) {
            this.ˊ = j;
        }

        public long ॱ() {
            return this.ˏ;
        }

        public void ˎ(long j) {
            this.ˏ = j;
        }

        public long ˋ() {
            return this.ˎ;
        }

        public void ॱ(long j) {
            this.ˎ = j;
        }

        public long ˎ() {
            return this.ˋ;
        }

        public void ˊ(long j) {
            this.ˋ = j;
        }
    }

    public bnu(SplitTask splitTask, SplitDownloadThreadInfo splitDownloadThreadInfo, bnx o_bnx) {
        this.ˋॱ = splitTask;
        this.ˏॱ = splitDownloadThreadInfo;
        this.ˊॱ = o_bnx;
        this.ʻ = true;
        this.ˊˋ = new a(this);
        this.ˊˊ.append(" rangeInfo=");
    }

    public SplitDownloadThreadInfo ˊ() {
        return this.ˏॱ;
    }

    private void ʼ() throws bnj {
        if (!this.ʻ) {
            throw new bnj(103, "thread download quit because  stopped");
        }
    }

    public boolean ˎ() {
        return this.ॱˊ;
    }

    public boolean ॱ() {
        return this.ॱॱ;
    }

    private boolean ᐝ() {
        return (this.ˏॱ.ॱॱ() - this.ˏॱ.ʻ()) + 1 > this.ˏॱ.ʽ();
    }

    private void ʻ() {
        if (this.ʻ) {
            synchronized (this.ˊॱ) {
                this.ˊॱ.ˎ();
            }
        }
    }

    private void ॱ(byte[] bArr, int i) {
        if (this.ˈ == 0) {
            int min = Math.min(4096, i);
            System.arraycopy(bArr, 0, this.ʽॱ, 0, min);
            this.ˈ = min;
            bnc.ˎ.ˋ("HiAppDownload", "setStartBytesData done");
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void ˏ(java.io.BufferedInputStream r17, java.io.RandomAccessFile r18) throws java.io.IOException, o.bnj {
        /*
        r16 = this;
        r2 = 8192; // 0x2000 float:1.14794E-41 double:4.0474E-320;
        r2 = new byte[r2];
        r6 = 1048576; // 0x100000 float:1.469368E-39 double:5.180654E-318;
        r7 = new byte[r6];
        r3 = 0;
        r4 = java.lang.System.currentTimeMillis();
        r8 = 500; // 0x1f4 float:7.0E-43 double:2.47E-321;
        r4 = r4 - r8;
        r8 = java.lang.System.currentTimeMillis();
        r0 = r16;
        r0.ॱˎ = r8;
        r8 = 0;
        r0 = r16;
        r0.ʻॱ = r8;
        r8 = 0;
        r0 = r16;
        r0.ᐝॱ = r8;
        r8 = 0;
        r0 = r16;
        r0.ॱᐝ = r8;
        r8 = 0;
        r0 = r16;
        r0.ʿ = r8;
        r8 = 0;
        r0 = r16;
        r0.ʼॱ = r8;
        r0 = r16;
        r8 = r0.ˏॱ;
        r8 = r8.ʽ();
        r0 = r16;
        r10 = r0.ˏॱ;
        r12 = java.lang.System.currentTimeMillis();
        r10.ʽ(r12);
    L_0x0048:
        r0 = r17;
        r10 = r0.read(r2);	 Catch:{ all -> 0x0062 }
        if (r10 <= 0) goto L_0x0154;
    L_0x0050:
        r11 = 1122; // 0x462 float:1.572E-42 double:5.543E-321;
        r0 = r16;
        r11 = r0.ॱ(r11);	 Catch:{ all -> 0x0062 }
        if (r11 == 0) goto L_0x0097;
    L_0x005a:
        r2 = new java.net.SocketTimeoutException;	 Catch:{ all -> 0x0062 }
        r4 = "mock SocketTimeoutException";
        r2.<init>(r4);	 Catch:{ all -> 0x0062 }
        throw r2;	 Catch:{ all -> 0x0062 }
    L_0x0062:
        r2 = move-exception;
        if (r3 <= 0) goto L_0x0096;
    L_0x0065:
        r0 = r16;
        r4 = r0.ˊˋ;	 Catch:{ IOException -> 0x0255 }
        r5 = 0;
        r4.ˎ(r7, r5, r3);	 Catch:{ IOException -> 0x0255 }
        r4 = 0;
        r0 = r18;
        r0.write(r7, r4, r3);	 Catch:{ IOException -> 0x0255 }
        r0 = r16;
        r0.ॱ(r7, r3);	 Catch:{ IOException -> 0x0255 }
        r0 = r16;
        r4 = r0.ˏॱ;	 Catch:{ IOException -> 0x0255 }
        r0 = r16;
        r5 = r0.ˏॱ;	 Catch:{ IOException -> 0x0255 }
        r6 = r5.ʽ();	 Catch:{ IOException -> 0x0255 }
        r8 = (long) r3;	 Catch:{ IOException -> 0x0255 }
        r6 = r6 + r8;
        r4.ˊ(r6);	 Catch:{ IOException -> 0x0255 }
        r0 = r16;
        r4 = r0.ʽ;	 Catch:{ IOException -> 0x0255 }
        r6 = (long) r3;	 Catch:{ IOException -> 0x0255 }
        r4 = r4 + r6;
        r0 = r16;
        r0.ʽ = r4;	 Catch:{ IOException -> 0x0255 }
        r16.ʻ();	 Catch:{ IOException -> 0x0255 }
    L_0x0096:
        throw r2;
    L_0x0097:
        r11 = 113; // 0x71 float:1.58E-43 double:5.6E-322;
        r0 = r16;
        r11 = r0.ॱ(r11);	 Catch:{ all -> 0x0062 }
        if (r11 == 0) goto L_0x00a9;
    L_0x00a1:
        r2 = new java.io.IOException;	 Catch:{ all -> 0x0062 }
        r4 = "mock IOException:unexpected end of stream";
        r2.<init>(r4);	 Catch:{ all -> 0x0062 }
        throw r2;	 Catch:{ all -> 0x0062 }
    L_0x00a9:
        r11 = 0;
        r0 = r16;
        r0.ͺ = r11;	 Catch:{ all -> 0x0062 }
        r11 = 0;
        r0 = r16;
        r0.ʾ = r11;	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r12 = r0.ᐝ;	 Catch:{ all -> 0x0062 }
        r14 = (long) r10;	 Catch:{ all -> 0x0062 }
        r12 = r12 + r14;
        r0 = r16;
        r0.ᐝ = r12;	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r12 = r0.ॱᐝ;	 Catch:{ all -> 0x0062 }
        r14 = (long) r10;	 Catch:{ all -> 0x0062 }
        r12 = r12 + r14;
        r0 = r16;
        r0.ॱᐝ = r12;	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r11 = r0.ˏॱ;	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r12 = r0.ॱᐝ;	 Catch:{ all -> 0x0062 }
        r11.ʻ(r12);	 Catch:{ all -> 0x0062 }
        r11 = r10 + r3;
        if (r11 > r6) goto L_0x00e1;
    L_0x00d6:
        r12 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x0062 }
        r14 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
        r14 = r14 + r4;
        r11 = (r12 > r14 ? 1 : (r12 == r14 ? 0 : -1));
        if (r11 <= 0) goto L_0x0119;
    L_0x00e1:
        if (r3 <= 0) goto L_0x0119;
    L_0x00e3:
        r0 = r16;
        r4 = r0.ˊˋ;	 Catch:{ IOException -> 0x01d3 }
        r5 = 0;
        r4.ˎ(r7, r5, r3);	 Catch:{ IOException -> 0x01d3 }
        r4 = 0;
        r0 = r18;
        r0.write(r7, r4, r3);	 Catch:{ IOException -> 0x01d3 }
        r0 = r16;
        r0.ॱ(r7, r3);	 Catch:{ IOException -> 0x01d3 }
        r4 = java.lang.System.currentTimeMillis();	 Catch:{ IOException -> 0x01d3 }
        r0 = r16;
        r11 = r0.ˏॱ;	 Catch:{ IOException -> 0x01d3 }
        r0 = r16;
        r12 = r0.ˏॱ;	 Catch:{ IOException -> 0x01d3 }
        r12 = r12.ʽ();	 Catch:{ IOException -> 0x01d3 }
        r14 = (long) r3;	 Catch:{ IOException -> 0x01d3 }
        r12 = r12 + r14;
        r11.ˊ(r12);	 Catch:{ IOException -> 0x01d3 }
        r0 = r16;
        r12 = r0.ʽ;	 Catch:{ IOException -> 0x01d3 }
        r14 = (long) r3;	 Catch:{ IOException -> 0x01d3 }
        r12 = r12 + r14;
        r0 = r16;
        r0.ʽ = r12;	 Catch:{ IOException -> 0x01d3 }
        r3 = 0;
        r16.ʻ();	 Catch:{ IOException -> 0x01d3 }
    L_0x0119:
        r11 = 0;
        java.lang.System.arraycopy(r2, r11, r7, r3, r10);	 Catch:{ all -> 0x0062 }
        r3 = r3 + r10;
        r16.ʼ();	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r10 = r0.ˏॱ;	 Catch:{ all -> 0x0062 }
        r10 = r10.ॱˊ();	 Catch:{ all -> 0x0062 }
        if (r10 == 0) goto L_0x01fe;
    L_0x012b:
        r0 = r16;
        r10 = r0.ˏॱ;	 Catch:{ all -> 0x0062 }
        r10 = r10.ॱॱ();	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r12 = r0.ˏॱ;	 Catch:{ all -> 0x0062 }
        r12 = r12.ʻ();	 Catch:{ all -> 0x0062 }
        r10 = r10 - r12;
        r12 = 1;
        r10 = r10 + r12;
        r0 = r16;
        r12 = r0.ॱᐝ;	 Catch:{ all -> 0x0062 }
        r12 = r12 + r8;
        r10 = r10 - r12;
        r12 = 0;
        r10 = (r10 > r12 ? 1 : (r10 == r12 ? 0 : -1));
        if (r10 >= 0) goto L_0x01fe;
    L_0x014b:
        r2 = o.bnc.ˎ;	 Catch:{ all -> 0x0062 }
        r4 = "HiAppDownload";
        r5 = "splitDownloadThreadInfo finished before stream ends for dynamic download";
        r2.ˋ(r4, r5);	 Catch:{ all -> 0x0062 }
    L_0x0154:
        r0 = r16;
        r2 = r0.ˊˊ;	 Catch:{ all -> 0x0062 }
        r4 = "|readCount=";
        r2 = r2.append(r4);	 Catch:{ all -> 0x0062 }
        r0 = r16;
        r4 = r0.ॱᐝ;	 Catch:{ all -> 0x0062 }
        r2 = r2.append(r4);	 Catch:{ all -> 0x0062 }
        r4 = " ";
        r2.append(r4);	 Catch:{ all -> 0x0062 }
        if (r3 <= 0) goto L_0x019f;
    L_0x016d:
        r0 = r16;
        r2 = r0.ˊˋ;	 Catch:{ IOException -> 0x0209 }
        r4 = 0;
        r2.ˎ(r7, r4, r3);	 Catch:{ IOException -> 0x0209 }
        r2 = 0;
        r0 = r18;
        r0.write(r7, r2, r3);	 Catch:{ IOException -> 0x0209 }
        r0 = r16;
        r0.ॱ(r7, r3);	 Catch:{ IOException -> 0x0209 }
        r0 = r16;
        r2 = r0.ˏॱ;	 Catch:{ IOException -> 0x0209 }
        r0 = r16;
        r4 = r0.ˏॱ;	 Catch:{ IOException -> 0x0209 }
        r4 = r4.ʽ();	 Catch:{ IOException -> 0x0209 }
        r8 = (long) r3;	 Catch:{ IOException -> 0x0209 }
        r4 = r4 + r8;
        r2.ˊ(r4);	 Catch:{ IOException -> 0x0209 }
        r0 = r16;
        r4 = r0.ʽ;	 Catch:{ IOException -> 0x0209 }
        r8 = (long) r3;	 Catch:{ IOException -> 0x0209 }
        r4 = r4 + r8;
        r0 = r16;
        r0.ʽ = r4;	 Catch:{ IOException -> 0x0209 }
        r3 = 0;
        r16.ʻ();	 Catch:{ IOException -> 0x0209 }
    L_0x019f:
        if (r3 <= 0) goto L_0x01d2;
    L_0x01a1:
        r0 = r16;
        r2 = r0.ˊˋ;	 Catch:{ IOException -> 0x0234 }
        r4 = 0;
        r2.ˎ(r7, r4, r3);	 Catch:{ IOException -> 0x0234 }
        r2 = 0;
        r0 = r18;
        r0.write(r7, r2, r3);	 Catch:{ IOException -> 0x0234 }
        r0 = r16;
        r0.ॱ(r7, r3);	 Catch:{ IOException -> 0x0234 }
        r0 = r16;
        r2 = r0.ˏॱ;	 Catch:{ IOException -> 0x0234 }
        r0 = r16;
        r4 = r0.ˏॱ;	 Catch:{ IOException -> 0x0234 }
        r4 = r4.ʽ();	 Catch:{ IOException -> 0x0234 }
        r6 = (long) r3;	 Catch:{ IOException -> 0x0234 }
        r4 = r4 + r6;
        r2.ˊ(r4);	 Catch:{ IOException -> 0x0234 }
        r0 = r16;
        r4 = r0.ʽ;	 Catch:{ IOException -> 0x0234 }
        r2 = (long) r3;	 Catch:{ IOException -> 0x0234 }
        r2 = r2 + r4;
        r0 = r16;
        r0.ʽ = r2;	 Catch:{ IOException -> 0x0234 }
        r16.ʻ();	 Catch:{ IOException -> 0x0234 }
    L_0x01d2:
        return;
    L_0x01d3:
        r2 = move-exception;
        r4 = o.bnc.ˎ;	 Catch:{ all -> 0x0062 }
        r5 = "HiAppDownload";
        r6 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0062 }
        r6.<init>();	 Catch:{ all -> 0x0062 }
        r8 = "write file failed:";
        r6 = r6.append(r8);	 Catch:{ all -> 0x0062 }
        r8 = r2.getMessage();	 Catch:{ all -> 0x0062 }
        r6 = r6.append(r8);	 Catch:{ all -> 0x0062 }
        r6 = r6.toString();	 Catch:{ all -> 0x0062 }
        r4.ˊ(r5, r6);	 Catch:{ all -> 0x0062 }
        r4 = new o.bnj;	 Catch:{ all -> 0x0062 }
        r5 = 121; // 0x79 float:1.7E-43 double:6.0E-322;
        r2 = r2.getMessage();	 Catch:{ all -> 0x0062 }
        r4.<init>(r5, r2);	 Catch:{ all -> 0x0062 }
        throw r4;	 Catch:{ all -> 0x0062 }
    L_0x01fe:
        r0 = r16;
        r10 = r0.ˋˊ;	 Catch:{ all -> 0x0062 }
        if (r10 != 0) goto L_0x0048;
    L_0x0204:
        r16.ʽ();	 Catch:{ all -> 0x0062 }
        goto L_0x0048;
    L_0x0209:
        r2 = move-exception;
        r4 = o.bnc.ˎ;	 Catch:{ all -> 0x0062 }
        r5 = "HiAppDownload";
        r6 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0062 }
        r6.<init>();	 Catch:{ all -> 0x0062 }
        r8 = "write file failed:";
        r6 = r6.append(r8);	 Catch:{ all -> 0x0062 }
        r8 = r2.getMessage();	 Catch:{ all -> 0x0062 }
        r6 = r6.append(r8);	 Catch:{ all -> 0x0062 }
        r6 = r6.toString();	 Catch:{ all -> 0x0062 }
        r4.ˊ(r5, r6);	 Catch:{ all -> 0x0062 }
        r4 = new o.bnj;	 Catch:{ all -> 0x0062 }
        r5 = 121; // 0x79 float:1.7E-43 double:6.0E-322;
        r2 = r2.getMessage();	 Catch:{ all -> 0x0062 }
        r4.<init>(r5, r2);	 Catch:{ all -> 0x0062 }
        throw r4;	 Catch:{ all -> 0x0062 }
    L_0x0234:
        r2 = move-exception;
        r3 = o.bnc.ˎ;
        r4 = "HiAppDownload";
        r5 = new java.lang.StringBuilder;
        r5.<init>();
        r6 = "write file failed:";
        r5 = r5.append(r6);
        r2 = r2.getMessage();
        r2 = r5.append(r2);
        r2 = r2.toString();
        r3.ˊ(r4, r2);
        goto L_0x01d2;
    L_0x0255:
        r3 = move-exception;
        r4 = o.bnc.ˎ;
        r5 = "HiAppDownload";
        r6 = new java.lang.StringBuilder;
        r6.<init>();
        r7 = "write file failed:";
        r6 = r6.append(r7);
        r3 = r3.getMessage();
        r3 = r6.append(r3);
        r3 = r3.toString();
        r4.ˊ(r5, r3);
        goto L_0x0096;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bnu.ˏ(java.io.BufferedInputStream, java.io.RandomAccessFile):void");
    }

    private void ʽ() throws bnj {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis >= this.ॱˎ + 3000) {
            this.ᐝॱ = ((this.ॱᐝ - this.ʻॱ) * 1000) / ((currentTimeMillis - this.ॱˎ) * AppSupportContentFlag.MMAPP_SUPPORT_XLS);
            if (this.ᐝॱ >= 30) {
                this.ʿ = false;
            } else if (!this.ʿ) {
                this.ʿ = true;
                this.ʼॱ = currentTimeMillis;
            } else if (currentTimeMillis - this.ʼॱ >= 20000 && doo.ॱॱ(bnl.ˏ().ॱ())) {
                throw ˎ(new bnj(125, "download speed too slow"));
            }
            this.ॱˎ = currentTimeMillis;
            this.ʻॱ = this.ॱᐝ;
        }
    }

    private void ˋ(int i, long j, long j2) throws bnj {
        if (i == -1) {
            throw ˎ(new bnj(108, " thread download failed,response null, lastUrl=" + this.ॱ));
        }
        if (ॱ(1061)) {
            i = 416;
        }
        if (ॱ(109)) {
            i = ResponseBean.NOT_FOUND;
        }
        bnj o_bnj;
        if (i == 416) {
            o_bnj = new bnj(106, "server file is wrong : 416 response [package= " + this.ˋॱ.ˎˎ() + ", rangeStart=" + j + ", rangeEnd=" + j2 + ", currentSize=" + this.ˋॱ.ʼॱ() + ", lastUrl=" + this.ॱ + "]");
            o_bnj.ˋ().put("httpResponseCode", String.valueOf(i));
            throw ˎ(o_bnj);
        } else if (i != 200 && i != 206) {
            o_bnj = new bnj(109, "thread download failed:bad http response [responseCode=" + i + ", lastUrl=" + this.ॱ + "]");
            o_bnj.ˋ().put("httpResponseCode", String.valueOf(i));
            throw ˎ(o_bnj);
        }
    }

    private void ˊ(int i, String str, String str2) throws bnj {
        long j = -1;
        this.ʼ = false;
        if (206 == i) {
            if (!dof.ˋ(str)) {
                j = bno.ˎ(str);
            }
        } else if (200 == i && !dof.ˋ(str2)) {
            try {
                j = Long.parseLong(str2);
            } catch (NumberFormatException e) {
                bnc.ˎ.ˊ("HiAppDownload", "checkServerFileByResponse exception:" + e.getMessage());
            }
        }
        if (j > 0) {
            if (ॱ(1062)) {
                j = 1;
            }
            if (j == this.ˋॱ.ʼॱ()) {
                this.ʼ = true;
                bnc.ˎ.ˋ("HiAppDownload", "lengthCheckedBeforeDownload");
                return;
            }
            String str3 = "server file length is wrong [package= " + this.ˋॱ.ˎˎ() + ", streamLength=" + j + ", storeSize=" + this.ˋॱ.ʼॱ() + ", lastUrl=" + this.ॱ + "]";
            bnc.ˎ.ˊ("HiAppDownload", str3);
            throw ˎ(new bnj(106, str3));
        }
    }

    private void ॱॱ() throws bnj {
        if (ॱ(129)) {
            throw new bnj(129, "mock no active network");
        }
        Context ॱ = bnl.ˏ().ॱ();
        if (ॱ != null && !doo.ˊ(ॱ)) {
            bnc.ˎ.ˋ("HiAppDownload", "thread download interrupted as no active network");
            throw new bnj(129, "no active network");
        }
    }

    private void ˋ(e eVar) throws IOException, bnj {
        Closeable randomAccessFile;
        Throwable th;
        Closeable closeable;
        Closeable ˊ = eVar.ˊ();
        long ˏ = eVar.ˏ();
        long ॱ = eVar.ॱ();
        long ˋ = eVar.ˋ();
        long ˎ = eVar.ˎ();
        if (ˊ != null) {
            try {
                Closeable bufferedInputStream = new BufferedInputStream(ˊ);
                try {
                    randomAccessFile = new RandomAccessFile(new File(this.ˋॱ.ˊˊ()), "rwd");
                    try {
                        randomAccessFile.seek(ˏ);
                        try {
                            ˏ((BufferedInputStream) bufferedInputStream, (RandomAccessFile) randomAccessFile);
                            long currentTimeMillis = System.currentTimeMillis() - ॱ;
                            ॱ = this.ˏॱ.ʽ() - ˋ;
                            if (this.ˏॱ.ॱˊ()) {
                                ˊॱ();
                            }
                            ˏ = (ˎ - ˏ) + 1;
                            if (ॱ(127)) {
                                ॱ = 1;
                            }
                            if (!(this.ˏॱ.ॱˊ() || ˏ == ॱ || ॱ >= FileUtil.LOCAL_REPORT_FILE_MAX_SIZE)) {
                                if (doo.ॱ(cvx.ˎ("ota.host"), 443)) {
                                    if (ˏ(this.ʽॱ, this.ˈ)) {
                                        throw ˎ(new bnj(127, "download possibly hijacked"));
                                    } else if (ॱ(127)) {
                                        throw ˎ(new bnj(127, "mock download possibly hijacked"));
                                    }
                                }
                                throw ˎ(new bnj(126, "local network error, not reachable"));
                            }
                            if (ॱ > 0) {
                                Map ˊ2 = ˊ(currentTimeMillis, ॱ);
                                ˊ2.put("retryType", this.ˊॱ.ˏ());
                                bni.ˊ(ˊ2, this.ˋॱ.ˋᐝ(), this.ˋॱ);
                            }
                            bny.ˎ(randomAccessFile);
                            bny.ˎ(ˊ);
                            bny.ˎ(bufferedInputStream);
                        } catch (Throwable th2) {
                            th = th2;
                            closeable = bufferedInputStream;
                            bny.ˎ(randomAccessFile);
                            bny.ˎ(ˊ);
                            bny.ˎ(closeable);
                            throw th;
                        }
                    } catch (IOException e) {
                        th = e;
                        bnc.ˎ.ˊ("HiAppDownload", "get file failed", th);
                        throw new bnj(110, th.getMessage());
                    }
                } catch (IOException e2) {
                    th = e2;
                    randomAccessFile = null;
                    bnc.ˎ.ˊ("HiAppDownload", "get file failed", th);
                    throw new bnj(110, th.getMessage());
                } catch (Throwable th3) {
                    th = th3;
                    randomAccessFile = null;
                    closeable = bufferedInputStream;
                    bny.ˎ(randomAccessFile);
                    bny.ˎ(ˊ);
                    bny.ˎ(closeable);
                    throw th;
                }
            } catch (Throwable th4) {
                th = th4;
                closeable = null;
                randomAccessFile = null;
                bny.ˎ(randomAccessFile);
                bny.ˎ(ˊ);
                bny.ˎ(closeable);
                throw th;
            }
        }
    }

    private void ˊॱ() {
        long ॱॱ = (this.ˏॱ.ॱॱ() - this.ˏॱ.ʻ()) + 1;
        if (this.ˏॱ.ʽ() > ॱॱ) {
            this.ˏॱ.ˊ(ॱॱ);
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void ͺ() throws o.bnj {
        /*
        r15 = this;
        r7 = 0;
        r5 = 0;
        r15.ͺ = r5;
        r0 = r15.ˋॱ;
        r0 = r0.ͺ();
        r15.ॱˋ = r0;
        r0 = o.bnc.ˎ;
        r1 = "HiAppDownload";
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r3 = "downloadOneRange begin :";
        r2 = r2.append(r3);
        r3 = r15.ˋॱ;
        r3 = r3.ˎˎ();
        r2 = r2.append(r3);
        r2 = r2.toString();
        r0.ˋ(r1, r2);
        r0 = new java.net.URL;	 Catch:{ MalformedURLException -> 0x007a }
        r1 = r15.ॱˋ;	 Catch:{ MalformedURLException -> 0x007a }
        r0.<init>(r1);	 Catch:{ MalformedURLException -> 0x007a }
        r0 = r0.getHost();	 Catch:{ MalformedURLException -> 0x007a }
        r6 = r0;
    L_0x0038:
        r15.ʾ = r5;
        r0 = r15.ˊ;
        r0.clear();
    L_0x003f:
        r0 = "";
        r15.ˎ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = "";
        r15.ॱ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = "";
        r15.ˏ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = 0;
        r15.ˈ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r15.ॱॱ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r15.ʼ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ˏॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.ʻ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r2 = r15.ˏॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r2 = r2.ʽ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r2 = r2 + r0;
        r0 = r15.ˏॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r4 = r0.ॱॱ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1));
        if (r0 <= 0) goto L_0x009b;
    L_0x006b:
        r0 = o.bnc.ˎ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = "HiAppDownload";
        r2 = "startPos is greater than endRange, skip";
        r0.ˋ(r1, r2);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r7 == 0) goto L_0x0079;
    L_0x0076:
        r7.close();
    L_0x0079:
        return;
    L_0x007a:
        r0 = move-exception;
        r1 = o.bnc.ˎ;
        r2 = "HiAppDownload";
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r4 = "downloadOneRange:";
        r3 = r3.append(r4);
        r0 = r0.getMessage();
        r0 = r3.append(r0);
        r0 = r0.toString();
        r1.ˊ(r2, r0);
        r6 = r7;
        goto L_0x0038;
    L_0x009b:
        r0 = o.bnc.ˎ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = "HiAppDownload";
        r8 = new java.lang.StringBuilder;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8.<init>();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = "downloadOneRange before connect :";
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r15.ˋॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r9.ˎˎ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = ", protocol=";
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r15.ˋॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r9.ˋˊ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = " range:";
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = r8.append(r2);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = "---";
        r8 = r8.append(r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = r8.append(r4);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = r8.toString();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0.ˋ(r1, r8);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ˏॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r10 = r0.ʽ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r12 = java.lang.System.currentTimeMillis();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ˊˊ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = " ";
        r0 = r0.append(r1);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.append(r2);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = "|";
        r0 = r0.append(r1);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.append(r4);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = "|";
        r0 = r0.append(r1);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0.append(r10);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ॱˋ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r15.ॱ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = new o.bno$d;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.<init>();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ॱˋ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ˋ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ॱ = r2;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ˊ = r4;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = 1;
        r1.ˎ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ॱॱ = r6;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r15.ˊॱ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.ˋ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r0 == 0) goto L_0x0145;
    L_0x0126:
        r0 = o.bnl.ˏ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.ॱˊ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.ʻ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ॱॱ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
    L_0x0134:
        r0 = 0;
        r0 = o.bno.ˎ(r0, r1);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r15.ʼ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r0 != 0) goto L_0x01c5;
    L_0x013e:
        if (r7 == 0) goto L_0x0079;
    L_0x0140:
        r7.close();
        goto L_0x0079;
    L_0x0145:
        r0 = r15.ʾ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r0 != 0) goto L_0x0134;
    L_0x0149:
        r0 = r15.ˊ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.containsKey(r6);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r0 == 0) goto L_0x0134;
    L_0x0151:
        r0 = r15.ˊ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = r0.get(r6);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = (java.util.List) r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1.ˏ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = o.bnc.ˎ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r8 = "HiAppDownload";
        r9 = new java.lang.StringBuilder;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9.<init>();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r14 = "DownloadThreadTask download ok3   start url=";
        r9 = r9.append(r14);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r14 = r15.ॱˋ;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r9.append(r14);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r9 = r9.toString();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0.ˏ(r8, r9);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r0 = 1;
        r15.ʾ = r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        goto L_0x0134;
    L_0x017b:
        r0 = move-exception;
        r1 = r7;
    L_0x017d:
        r2 = r15.ʻ;	 Catch:{ all -> 0x0285 }
        if (r2 == 0) goto L_0x01bb;
    L_0x0181:
        r2 = o.bnc.ˎ;	 Catch:{ all -> 0x0285 }
        r3 = "HiAppDownload";
        r4 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0285 }
        r4.<init>();	 Catch:{ all -> 0x0285 }
        r5 = "catch IO exception in downloadOneRange: ";
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r5 = r0.getMessage();	 Catch:{ all -> 0x0285 }
        r5 = o.bno.ˏ(r5);	 Catch:{ all -> 0x0285 }
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r5 = ", sereverIp=";
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r5 = r15.ˎ;	 Catch:{ all -> 0x0285 }
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r5 = ", lastUrl = ";
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r5 = r15.ॱ;	 Catch:{ all -> 0x0285 }
        r4 = r4.append(r5);	 Catch:{ all -> 0x0285 }
        r4 = r4.toString();	 Catch:{ all -> 0x0285 }
        r2.ˊ(r3, r4);	 Catch:{ all -> 0x0285 }
    L_0x01bb:
        r15.ॱ(r0);	 Catch:{ all -> 0x0285 }
        if (r1 == 0) goto L_0x003f;
    L_0x01c0:
        r1.close();
        goto L_0x003f;
    L_0x01c5:
        r1 = r0.ॱ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = o.bnq.ˊ(r1);	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r15.ˎ = r1;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = r0.ˊ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        if (r1 != 0) goto L_0x01e9;
    L_0x01d5:
        r0 = r0.ˎ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        throw r0;	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
    L_0x01da:
        r0 = move-exception;
    L_0x01db:
        r1 = r0 instanceof o.bnj;	 Catch:{ all -> 0x01e2 }
        if (r1 == 0) goto L_0x0257;
    L_0x01df:
        r0 = (o.bnj) r0;	 Catch:{ all -> 0x01e2 }
        throw r0;	 Catch:{ all -> 0x01e2 }
    L_0x01e2:
        r0 = move-exception;
    L_0x01e3:
        if (r7 == 0) goto L_0x01e8;
    L_0x01e5:
        r7.close();
    L_0x01e8:
        throw r0;
    L_0x01e9:
        r8 = r0.ˏ();	 Catch:{ IOException -> 0x017b, Exception -> 0x01da }
        r1 = r8.ˊ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = "dl-from";
        r0 = r8.ˋ(r0);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r9 = "Server";
        r9 = r8.ˋ(r9);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r15.ॱ(r0, r9);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r8.ˎ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r0.toString();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r15.ˋ = r0;	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r8.ॱ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r0.ˏ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r0.toString();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r15.ॱ = r0;	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r15;
        r0.ˋ(r1, r2, r4);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = "Content-Range";
        r0 = r8.ˋ(r0);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r9 = "Content-Length";
        r9 = r8.ˋ(r9);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r15.ˊ(r1, r0, r9);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r8.ᐝ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r0.ˎ();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1 = new o.bnu$e;	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.<init>();	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.ˎ(r0);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.ˏ(r2);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.ˎ(r12);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.ॱ(r10);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r1.ˊ(r4);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r0 = r15.ˏॱ;	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r2 = 0;
        r0.ˊ(r2);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        r15.ˋ(r1);	 Catch:{ IOException -> 0x028d, Exception -> 0x0289, all -> 0x0281 }
        if (r8 == 0) goto L_0x0079;
    L_0x0252:
        r8.close();
        goto L_0x0079;
    L_0x0257:
        r0 = o.bny.ˎ(r0);	 Catch:{ all -> 0x01e2 }
        r1 = o.bnc.ˎ;	 Catch:{ all -> 0x01e2 }
        r2 = "HiAppDownload";
        r3 = new java.lang.StringBuilder;	 Catch:{ all -> 0x01e2 }
        r3.<init>();	 Catch:{ all -> 0x01e2 }
        r4 = "unknown exception:\n";
        r3 = r3.append(r4);	 Catch:{ all -> 0x01e2 }
        r3 = r3.append(r0);	 Catch:{ all -> 0x01e2 }
        r3 = r3.toString();	 Catch:{ all -> 0x01e2 }
        r1.ˏ(r2, r3);	 Catch:{ all -> 0x01e2 }
        r1 = new o.bnj;	 Catch:{ all -> 0x01e2 }
        r2 = 111; // 0x6f float:1.56E-43 double:5.5E-322;
        r1.<init>(r2, r0);	 Catch:{ all -> 0x01e2 }
        r0 = r15.ˎ(r1);	 Catch:{ all -> 0x01e2 }
        throw r0;	 Catch:{ all -> 0x01e2 }
    L_0x0281:
        r0 = move-exception;
        r7 = r8;
        goto L_0x01e3;
    L_0x0285:
        r0 = move-exception;
        r7 = r1;
        goto L_0x01e3;
    L_0x0289:
        r0 = move-exception;
        r7 = r8;
        goto L_0x01db;
    L_0x028d:
        r0 = move-exception;
        r1 = r8;
        goto L_0x017d;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bnu.ͺ():void");
    }

    private boolean ˏ(byte[] bArr, int i) {
        if (i > 4096) {
            i = 4096;
        }
        try {
            String replaceAll = new String(bArr, 0, i, "UTF-8").toUpperCase(Locale.getDefault()).replaceAll("\\s*", "");
            if (replaceAll.indexOf("<HEAD") < 0 || replaceAll.indexOf("<BODY") < 0 || replaceAll.indexOf("<HTML") < 0) {
                return false;
            }
            return true;
        } catch (UnsupportedEncodingException e) {
            bnc.ˎ.ˋ("HiAppDownload", "isHtml UnsupportedEncodingException");
            return false;
        }
    }

    private void ॱ(IOException iOException) throws bnj {
        int i = 1;
        int i2 = 0;
        ʼ();
        Context ॱ = bnl.ˏ().ॱ();
        if (ॱ == null || doo.ˊ(ॱ)) {
            int ˋ = ˋ(iOException);
            String ˏ = bno.ˏ(iOException.getMessage());
            int ˏ2 = dmv.ˏ(0, iOException);
            if (bno.ˋ((Exception) iOException)) {
                this.ͺ++;
                ˋ = 112;
            } else if (ˎ(ˋ)) {
                this.ͺ++;
            } else {
                i2 = ˏ2 > 0 ? ˋ(iOException, ˏ2) : 1;
            }
            if (this.ͺ <= 2) {
                i = i2;
            }
            if (i != 0) {
                bnj o_bnj = new bnj(ˋ, ˏ);
                if (doo.ʻ(ॱ) && doo.ॱ(ॱ) && ˋ != 112) {
                    o_bnj.ˋ().put("apn", ˋ(ॱ));
                }
                throw ˎ(o_bnj);
            }
            return;
        }
        bnc.ˎ.ˋ("HiAppDownload", "thread download interrupted as no active network");
        throw new bnj(129, "no active network");
    }

    private String ˋ(Context context) {
        String str = "ApnNode is null";
        try {
            d ˊ = dom.ˊ(context);
            if (ˊ == null) {
                return str;
            }
            if (ˊ.ˋ() == null) {
                return "Null";
            }
            return ˊ.ˋ();
        } catch (SecurityException e) {
            Logger.ˋ("HiAppDownload", "getApnInfo(), SecurityException: " + e.toString());
            return str;
        }
    }

    private boolean ˋ(IOException iOException, int i) {
        try {
            String host = new URL(this.ॱˋ).getHost();
            if (bni.ॱ(host) || this.ʾ) {
                return true;
            }
            List ˎ = dmv.ˎ(host, iOException, i);
            if (ˎ.size() <= 0) {
                return true;
            }
            this.ˊ.put(host, ˎ);
            bnc.ˎ.ˋ("HiAppDownload", "download ok3 dnkeeper error code:" + i + " iplist=" + ˎ.toString());
            return false;
        } catch (Throwable e) {
            bnc.ˎ.ˊ("HiAppDownload", "MalformedURLException", e);
            return true;
        }
    }

    private boolean ˎ(int i) {
        return i == 1132 || i == 1133 || i == 1134 || i == 1130 || i == 1139;
    }

    private void ॱ(String str, String str2) {
        if (!dof.ˋ(str)) {
            this.ˏ = str;
        } else if (dof.ˋ(str2)) {
            this.ˏ = "";
        } else {
            this.ˏ = str2;
        }
    }

    private int ˋ(IOException iOException) {
        if (iOException == null) {
            return 113;
        }
        if (iOException instanceof SSLProtocolException) {
            return 1139;
        }
        String message = iOException.getMessage();
        if (message == null) {
            return 113;
        }
        if (message.contains("unexpected end of stream")) {
            return 1130;
        }
        if (message.contains("Unable to resolve host")) {
            return 1131;
        }
        if (message.contains("Read error")) {
            return 1132;
        }
        if (message.contains("Connection reset")) {
            return 1133;
        }
        if (message.contains("Software caused connection abort")) {
            return 1134;
        }
        if (message.contains("failed to connect to")) {
            return 1135;
        }
        if (message.contains("No route to host ")) {
            return 1136;
        }
        if (message.contains("Network is unreachable")) {
            return 1137;
        }
        if (message.contains("Connection refused")) {
            return 1138;
        }
        return 113;
    }

    private bnj ˎ(bnj o_bnj) {
        o_bnj.ˋ().put("serverIp", this.ˎ);
        o_bnj.ˋ().put("dlFrom", this.ˏ);
        o_bnj.ˋ().put("lastUrl", this.ॱ);
        o_bnj.ˋ().put("httpVersion", this.ˋ);
        o_bnj.ˋ().put("errorCode", String.valueOf(o_bnj.ˊ()));
        o_bnj.ˋ().put("errorMessage", o_bnj.ˏ());
        return o_bnj;
    }

    private Map<String, String> ˊ(long j, long j2) {
        Map<String, String> hashMap = new HashMap();
        hashMap.put("serverIp", this.ˎ);
        hashMap.put("dlFrom", this.ˏ);
        hashMap.put("lastUrl", this.ॱ);
        hashMap.put("httpVersion", this.ˋ);
        hashMap.put("errorCode", String.valueOf(200));
        hashMap.put("errorMessage", "");
        hashMap.put("totalTime", String.valueOf(j));
        hashMap.put("sizeDownload", String.valueOf(j2));
        hashMap.put("isCharging", this.ˋॱ.ˋ() ? "1" : "0");
        return hashMap;
    }

    public void ˋ() {
        this.ʻ = false;
    }

    public void run() {
        Process.setThreadPriority(10);
        bnc.ˎ.ˋ("HiAppDownload", "one download thread begin: " + ˋॱ());
        do {
            try {
                ͺ();
                if (!this.ʻ) {
                    break;
                }
            } catch (bnj e) {
                this.ॱॱ = true;
                ˊ(e);
                bnc.ˎ.ˊ("HiAppDownload", "one download thread end:" + ˋॱ() + ", errorCode:" + e.ˊ() + ", errorMsg:" + e.getMessage());
                return;
            }
        } while (ᐝ());
        this.ॱॱ = true;
        this.ॱˊ = true;
        bnc.ˎ.ˋ("HiAppDownload", "one download thread end:" + ˋॱ());
        ˏॱ();
    }

    private String ˋॱ() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(" package=").append(this.ˋॱ.ˎˎ()).append(", splitId=").append(this.ˋॱ.ˊˋ()).append(", start = ").append(this.ˏॱ.ʻ()).append(", end = ").append(this.ˏॱ.ॱॱ()).append(" , totalRead = ").append(this.ᐝ).append(", totalWrite=").append(this.ʽ);
        return stringBuffer.toString();
    }

    private void ˊ(bnj o_bnj) {
        if (this.ʻ) {
            synchronized (this.ˊॱ) {
                this.ˏॱ.ˏ(this.ˊˊ.toString());
                this.ˊॱ.ˊ(o_bnj);
            }
        }
    }

    private void ˏॱ() {
        if (this.ʻ) {
            synchronized (this.ˊॱ) {
                this.ˏॱ.ˏ(this.ˊˊ.toString());
                this.ˊॱ.ॱ();
            }
        }
    }

    private boolean ॱ(int i) {
        if (bny.ˎ(i)) {
            int ˏ = bns.ॱ().ˏ();
            if (ˏ <= 0 || ˏ == this.ˊॱ.ˊ()) {
                return true;
            }
        }
        return false;
    }

    public void ˊ(boolean z) {
        this.ˋˊ = z;
    }

    public Future<?> ˏ() {
        return this.ˉ;
    }

    public void ˏ(Future<?> future) {
        this.ˉ = future;
    }
}
